$().ready(function(){
	// 事件绑定
	InitPageEvent();
	// 页面初始化
	InitPageInfo();

});

/**
 * 事件绑定
 */
function InitPageEvent() {
    $(".deleteBtn").click(__deleteHandler).easyconfirm({
        locale: {
            title: '操作确认',
            text: '您确定要删除这篇电子版么？',
            button: ['取消', '是的，确定删除']
        }
    });
    $("[type='checkbox']").click(__recommendedHandler);
}

/**
 * 页面信息初始化
 */
function InitPageInfo() {
	$("tbody td").buttonset();
}


/**
 * 删除
 */
var __deleteHandler = function(){
    var tmp = $(this);
    $.post("/action/master/DeletePartyBuilding ", {
        Action: "post",
        id: tmp.attr("href")
    }, function(data, textStatus){
        if (!data.success) {
            $(".loadingbox").empty();
            $(".loadingbox").append(loadingTpl, {
                icoType: 'fail',
                loadIcon: '',
                msgHtml: data.message
            });
            $(".loadingbox").delay(3000).fadeOut(600);
        }
        else {
            $(".loadingbox").empty();
            $(".loadingbox").append(loadingTpl, {
                icoType: "succ",
                loadIcon: "",
                msgHtml: data.message
            });
            $(".loadingbox").fadeIn(50);
            $(".loadingbox").delay(2000).fadeOut(600);
            tmp.parents('tr').effect("highlight", {
                color: "#F00"
            }, 800, function(){
                $(this).remove();
      //          resetEvenColor();
            });
        }
    }, "json");
    return false;
}
	
var __recommendedHandler = function(e){
    var tmp = $(this);
    var action = "/action/master/unArticleTopic";
    if (tmp.is(':checked')) {
        action = "/action/master/setArticleTopic";
    }
    $.post(action, {
        Action: "post",
        id: tmp.val()
    }, function(data, textStatus){
        if (!data.success) {
            $(".loadingbox").empty();
            $(".loadingbox").append(loadingTpl, {
                icoType: 'fail',
                loadIcon: '',
                msgHtml: data.message
            });
            $(".loadingbox").delay(3000).fadeOut(600);
        }
        else {
            $(".loadingbox").empty();
            $(".loadingbox").append(loadingTpl, {
                icoType: "succ",
                loadIcon: "",
                msgHtml: data.message
            });
            $(".loadingbox").fadeIn(50);
            $(".loadingbox").delay(2000).fadeOut(600);
        }
    }, "json");
}